﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Adex;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using MediaMonitor.Common;

namespace MediaMonitor.SiteFiles
{
    public partial class Outdoor : Adex.BasePage
    {
        public string curVideo;
        public int width = 600;
        public int height = 700;

        public string filename;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                string pvID = Utility.GetRequestedVal("pvid", "0");
                string imgType = Utility.GetRequestedVal("t", "s");

                width = Utility.ToInt(Utility.GetRequestedVal("w", width.ToString())) - 20;
                height = Utility.ToInt(Utility.GetRequestedVal("h", height.ToString())) - 25;

                string outdoorFile = Utility.GetRequestedVal("file", "");

                ProdVersion pv = new ProdVersion(pvID);

                if (imgType == "s")
                {
                    if (CheckOutdoorFileAvailability(outdoorFile))
                    {
                        filename = "../outdoor/" + outdoorFile;
                        //width = 600;
                        //height = 700;
                        pnlVideo.Visible = true;
                        pnlNoVideo.Visible = false;
                    }
                    else
                    {
                        pnlNoVideo.Visible = true;
                        lblMsg.Text = "Picture not found";
                        pnlVideo.Visible = false;
                    }
                }
                else
                {
                    //only admin can view full sized videos
                    string[] uRoles = AppUser.GetUserRoles(AppUser.CurrUserID);
                    bool allowed = false;

                    if (uRoles.Length > 0)
                        if (uRoles[0] == "admin")
                            allowed = true;

                    string odid = Utility.GetRequestedVal("odid", "0");
                    OrderDetail ordItm = new OrderDetail(odid);
                    if (ordItm.ProdVersionID.ToString() == pvID)
                        allowed = true;

                    if (imgType == "f" && allowed == true)
                    {
                        if (Utility.ToStr(outdoorFile) != "" && CheckOutdoorFileAvailability(outdoorFile))
                        {
                            filename = "../outdoor/" + outdoorFile;
                            pnlVideo.Visible = true;
                            pnlNoVideo.Visible = false;
                            //width = 600;
                            //height = 700;
                        }
                        else
                        {
                            pnlNoVideo.Visible = true;
                            lblMsg.Text = "Outdoor Picture not found";
                            pnlVideo.Visible = false;
                        }
                    }
                    else
                    {
                        pnlNoVideo.Visible = true;
                        lblMsg.Text = "You dont have permissions to see the full size Outdoor Image";
                        pnlVideo.Visible = false;
                    }
                }

            }
        }

        private bool CheckOutdoorFileAvailability(string fileName)
        {
            return File.Exists(Server.MapPath("../outdoor/" + fileName));
        }
    }
}